
	
	** Append waves
		
		use "$dir/data/NGA_w1p_individual.dta", clear
		ren w1p_* *
		gen wave="w1p"
		tempfile data
		save `data', replace
		
		qui foreach wave in w1h w2p w2h w3p w3h w4p w4h {
			use "$dir/data/NGA_`wave'_individual.dta", clear
			ren `wave'_* *
			gen wave="`wave'"
			append using `data'
			save `data', replace
		}
		
	** Are individual ids consistent across rounds?
		bys hhid indiv: egen temp_fem=mean(female)		
			// in >99% of cases, female is coded the same
		bys hhid indiv: egen birthyear_min=min(birthyear)
		bys hhid indiv: egen birthyear_max=max(birthyear)
		gen birthyear_gap=birthyear_max-birthyear_min
			// in ~50% of cases, max and min birth years given within 2 years
			// in ~90% of cases, max and min birth years given within 10 years
		bys hhid indiv: egen temp_birthyear=sd(birthyear)
		
		bys hhid indiv: egen c_birthyear=mean(birthyear)
		replace c_birthyear=floor(c_birthyear) 
	
	** Cohort group
		gen cohort5=floor(birthyear/5)*5
		gen cohort10=floor(birthyear/10)*10
		
	** Age groups
		replace age=. if age<0
		gen age_group5=floor(age/5)*5
		gen age_group10=floor(age/10)*10
		
		replace age_group5=80 if age_group5>80 & !missing(age_group5)
		replace age_group10=80 if age_group10>80 & !missing(age_group10)
		
	** Cohort sample inclusion
		bys cohort5 age_group5: gen temp=_N
		gen insample5=temp>=100
		drop temp
		bys cohort10 age_group10: gen temp=_N
		gen insample10=temp>=100
		drop temp
		
		tab cohort5 age_group5 if insample5==1
		tab cohort10 age_group10 if insample10==1
		
	** Any work
		egen work_any=rowmax(work_outsideHH work_agHH work_bizHH)
		
	** Multigenerational household
		gen hh_multigen=(hh_under12==1 & hh_over60==1) 
		
	** Skipped generation household
		gen hh_skipgen=(hh_under12==1 & hh_over60==1 & hh_12to60==0)
		
	** Lives alone
		gen lives_alone=(hhsize_fromcons==1)
		
	** Urban status
		gen urban=geo_urban
		
	** Disability
		gen disability=(																	 	 ///
			diff_seei==1 | 																	 	 ///
			diff_hear==1 | 																	     ///
			diff_walk_clim==1 | 															     ///
			diff_reme==1 | 																	     ///
			diff_self_care==1 |																	 ///
			diff_comm ==1																		 ///
			)
		replace disability=. if (														         ///
			missing(diff_seei) &																 ///
			missing(diff_hear) & 														     	 ///
			missing(diff_walk_clim) & 														 	 ///
			missing(diff_reme) &																 ///
			missing(diff_self_care) &														     ///
			missing(diff_comm)       															 ///
			)
			
		drop conspc
		
	save "$dir/data/nga.dta", replace
